package com.john.bms.controller.system;

import com.john.bms.model.result.RequestResult;
import com.john.bms.model.system.menu.MenuTreeBO;
import com.john.bms.service.system.MenuService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import static com.john.bms.utils.CollectionUtils.map;

/**
 * @Author:张家小帅哥
 * @Date:2020/6/6
 * @Version:1.0
 * @Description:主页
 */
@RestController
@RequestMapping("/main")
public class MainController {

    @Resource
    private MenuService menuService;

    @GetMapping("treeList")
    public RequestResult treeList() {

        List<MenuTreeBO> treeList = menuService.getTreeList();

        return RequestResult.of(map(treeList, "data"));
    }

    @GetMapping("menus")
    public RequestResult menus() {
//        Session session = Jurisdiction.getSession();
//        SysUser user = (SysUser)session.getAttribute(BmsConst.SESSION_USER);
        HashMap<String, Object> map = new HashMap<>();
        HashMap<String, Object> map2 = new HashMap<>();
        HashMap<String, Object> map3 = new HashMap<>();
        HashMap<String, Object> map4 = new HashMap<>();
        HashMap<String, Object> map5 = new HashMap<>();
        map.put("id", 101);
        map.put("authName", "商品管理");
        map.put("path", "goods");
        map.put("icon", "el-icon-s-goods");

        map4.put("id", 234);
        map4.put("authName", "添加");
        map4.put("icon", "el-icon-menu");
        map4.put("path", "shopList");
        map.put("children", Arrays.asList(map4));

        map2.put("id", 125);
        map2.put("authName", "用户管理");
        map2.put("icon", "el-icon-s-custom");
        map2.put("path", "user");

        map5.put("id", 235);
        map5.put("authName", "用户列表");
        map5.put("icon", "el-icon-menu");
        map5.put("path", "userList");
        map2.put("children", Arrays.asList(map5));

        map3.put("id", 103);
        map3.put("authName", "权限管理");
        map3.put("path", "rights");
        map3.put("icon", "el-icon-setting");
        map3.put("children", Arrays.asList("1", "2"));
        List<HashMap<String, Object>> hashMaps = Arrays.asList(map, map2, map3);
        return RequestResult.of(map(hashMaps, "data")).setCode(20000).setMessage("获取菜单列表成功！");
    }
}
